package com.lizhanglong.androidtest;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class DefaultActionsActivity extends AppCompatActivity {

    final String[] Urls = new String[]{
            "http://www.baidu.com",
            "https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png",
            "https://dev.cloudapps02.abb.com.cn/AppPortal/SetupPackages/NaviBus.apk",
            "https://www.baidu.com/cache/sethelp/help.html",
    };
    Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_default_actions);
        context = this;
        ListView listView = (ListView) findViewById(R.id.list_defaultActions);
        listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, Urls));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String result = parent.getItemAtPosition(position).toString(); //获取选择项的值
                Toast.makeText(context, "点击了 " + result, Toast.LENGTH_SHORT).show();//输出选中项消息
                Intent intent = new Intent();
                intent.setAction("android.intent.action.VIEW");
                Uri content_url = Uri.parse(result);
                intent.setData(content_url);
                startActivity(intent);
            }
        });
    }
}
